package util;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.jupiter.api.Test;

import java.io.InputStream;

/**
 * @program: Mybatis201759225309
 * @description: Mybatis
 * @author: Xiaozhuoer
 * @create: 2021-04-12 10:21
 **/

public class MybatisUtil {
    public static SqlSession getSqlSession(){
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        ClassLoader loader = MybatisUtil.class.getClassLoader();
        InputStream inputStream = loader.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory factory = builder.build(inputStream);
        SqlSession session = factory.openSession();
        return session;
    }
}
